package vn.ivs.taxiapp.fragments;

import java.util.ArrayList;

import vn.ivs.taxiapp.R;
import vn.ivs.taxiapp.adapters.S006ListViewAdapter;
import vn.ivs.taxiapp.application.BaseApplication;
import vn.ivs.taxiapp.models.Bookmark;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class S006Fragment extends Fragment implements OnItemClickListener {
	private ListView mS006ListView;
	private ArrayList<Bookmark> mListBookmark;
	private TextView tvHeaderTitle;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_s006, container, false);
		// header
		tvHeaderTitle = (TextView) getActivity().findViewById(
				R.id.tvHeaderTitle);
		tvHeaderTitle.setText(getString(R.string.temp_s006_bookmark));

		mS006ListView = (ListView) v.findViewById(R.id.s006_listview);
		mS006ListView.setOnItemClickListener(this);

		// Mockup
		createTempBookmarkList();
		mS006ListView.setAdapter(new S006ListViewAdapter(getActivity(),
				mListBookmark));
		return v;
	}

	private void createTempBookmarkList() {
		ArrayList<Bookmark> list = new ArrayList<Bookmark>();
		Bookmark item;
		for (int i = 0; i < 4; i++) {
			item = new Bookmark();
			item.setName(getResources().getString(R.string.temp_s008_name)
					+ " " + i);
			item.setDescription(getResources().getString(
					R.string.temp_s008_desciption)
					+ " " + i);
			list.add(item);
		}
		mListBookmark = list;

	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		BaseApplication.mCurrentBookmark = mListBookmark.get(position);
		// Create new fragment and transaction
		Fragment newFragment = new S007Fragment();
		FragmentTransaction transaction = getFragmentManager()
				.beginTransaction();

		// Replace whatever is in the fragment_container view with this
		// fragment,
		// and add the transaction to the back stack
		transaction.add(android.R.id.tabcontent, newFragment);
		transaction.addToBackStack(null);

		// Commit the transaction
		transaction.commit();
	}

}
